/**
 * Created by ybq on 16-1-8.
 */

function _fomatflow(flow) {

    if (flow == 0) {
        return flow + "B/S"
    }
    var flownum = flow * 1
    var t = flownum >> 30;
    if (t > 0) {
        return (t + (flownum & ((1 << 30) - 1)) / (1 << 30)).toFixed(2) + "G/S"
    } else {
        t = flownum >> 20;
        if (t > 0) {
            return (t + (flownum & ((1 << 20) - 1)) / (1 << 20)).toFixed(2) + "M/S"
        } else {
            t = flownum >> 10
            if (t > 0) {
                return (t + (flownum & ((1 << 10) - 1)) / (1 << 10)).toFixed(2) + "K/S"
            } else {
                return flownum + "B/S"
            }
        }
    }
}

function _fomatDataSize(flow) {
    if (flow == 0) {
        return flow + "B"
    }
    var flownum = flow * 1
    var t = flownum >> 30;
    if (t > 0) {
        return (t + (flownum & ((1 << 30) - 1)) / (1 << 30)).toFixed(2) + "G"
    } else {
        t = flownum >> 20;
        if (t > 0) {
            return (t + (flownum & ((1 << 20) - 1)) / (1 << 20)).toFixed(2) + "M"
        } else {
            t = flownum >> 10
            if (t > 0) {
                return (t + (flownum & ((1 << 10) - 1)) / (1 << 10)).toFixed(2) + "K"
            } else {
                return flownum + "B"
            }
        }
    }
}

//创建过滤器
app.register.provide.value("fomatflow", _fomatflow)
//创建过滤器
app.register.provide.value("fomatDataSize", _fomatDataSize)
app.register.filter("fomatflow", function (fomatflow) {
    return function (text) {
        return fomatflow(text)
    }
});
app.register.filter("fomatDataSize", function (fomatDataSize) {
    return function (text) {
        return fomatDataSize(text)
    }
});



//创建过滤器
app.register.provide.value("sendfrom2zh", function (name) {
    if (name == "c_s") {
        return "客户-服务"
    } else if (name = "s_c") {
        return "服务-客户"
    }
    return "错误类型";
})
app.register.filter("sendfrom2zh", function (sendfrom2zh) {
    return function (text) {
        return sendfrom2zh(text)
    }
});
